#include "extension.h"
#include <QtWidgets>

Extension::Extension(QWidget *parent)
    : QDialog(parent)
{
    setWindowTitle(tr("Extension Dialog"));

    createBaseInfo();
    createDetailInfo();

    QVBoxLayout *layout = new QVBoxLayout;
    layout->addWidget(baseWidget);
    layout->addWidget(detailWidget);
    layout->setSizeConstraint(QLayout::SetFixedSize);
    layout->setSpacing(10);
    setLayout(layout);
}

Extension::~Extension()
{
}

void Extension::createBaseInfo()
{
    baseWidget = new QWidget;

    QLabel *nameLabel = new QLabel(tr("Name:"));
    QLineEdit *nameEdit = new QLineEdit;
    QLabel *sexLabel = new QLabel(tr("Sex:"));
    QComboBox *sexComboBox = new QComboBox;
    sexComboBox->addItem(tr("male"));
    sexComboBox->addItem(tr("female"));

    QPushButton *okButton = new QPushButton(tr("OK"));
    QPushButton *detailButton = new QPushButton(tr("Detail"));
    connect(detailButton, SIGNAL(clicked()),this,SLOT(slotExtension()));

    QDialogButtonBox *btnBox = new QDialogButtonBox(Qt::Vertical);
    btnBox->addButton(okButton, QDialogButtonBox::ActionRole);
    btnBox->addButton(detailButton, QDialogButtonBox::ActionRole);


    QGridLayout *layout=new QGridLayout();

    layout->addWidget(nameLabel,0,0);
    layout->addWidget(nameEdit,0,1);
    layout->addWidget(okButton,0,2);
    layout->addWidget(sexLabel,1,0);
    layout->addWidget(sexComboBox,1,1);
    layout->addWidget(detailButton,1,2);


    baseWidget->setLayout(layout);

}

void Extension::createDetailInfo()
{

    detailWidget = new QWidget;

    QLabel *label1= new QLabel(tr("Age:"));
    QLineEdit *ageEdit = new QLineEdit;
    ageEdit->setText("30");
    QLabel *label2 = new QLabel(tr("Department:"));
    QComboBox *deptComboBox = new QComboBox;
    deptComboBox->addItem(tr("dept1"));
    deptComboBox->addItem(tr("dept2"));
    deptComboBox->addItem(tr("dept3"));
    deptComboBox->addItem(tr("dept4"));
    QLabel *label3 = new QLabel(tr("Email:"));
    QLineEdit *edit = new QLineEdit;

    QGridLayout *layout = new QGridLayout();
    layout->addWidget(label1,0,0);
    layout->addWidget(ageEdit,0,1);
    layout->addWidget(label2,1,0);
    layout->addWidget(deptComboBox,1,1);
    layout->addWidget(label3,2,0);
    layout->addWidget(edit,2,1);

    detailWidget->setLayout(layout);
    detailWidget->hide();

}


void Extension::slotExtension()
{

    if(detailWidget->isHidden())
    {
        detailWidget->show();

    }
    else
    {
        detailWidget->hide();
    }
}

